<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
    <script type='text/javascript' src='js/vue.js'></script>
</head>
<body>
    <div id='app'>
        {{msg}}
        <brother></brother>
        <sister></sister>
    </div>
    <script type='text/javascript'>
        // 注册一个事件中心
        var hero = new Vue()
        var brother = {
            data() {
                return {
                    bro:''
                }
            },
            template: `<div @click="bTs">这是兄嘚组件======={{bro}}</div>`,
            methods: {
                bTs() {
                    hero.$emit('bro-event','恨妹不成穹！')
                }
            },
            mounted() {
                hero.$on('sis-event',mess => {
                    this.bro = mess
                })
            }
        }
        var sister = {
            data() {
                return {
                    sis: ''
                }
            },
            template: `<div @click="sTb">这是妹妹组件======={{sis}}</div>`,
            methods: {
                sTb() {
                    hero.$emit('sis-event','穹妹爱着欧尼酱！')
                }
            },
            mounted() {
                hero.$on('bro-event',val => {
                    this.sis = val;
                })
            }
        }
        var vm = new Vue({
            el: '#app',
            data: {
                msg: 'Hello Vue'
            },
            components: {
                brother,
                sister
            }
        });
    </script>
</body>
</html>